﻿using ET.DBCommon;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ET.DBCommon.Model;
using ET.DBCommon.DAL;
using NPOI.SS.Formula.Functions;

namespace ET.ScoreTeacherClient.Views
{
    /// <summary>
    /// SceneFile.xaml 的交互逻辑
    /// </summary>
    public partial class CommandEdit : UserControl, INotifyPropertyChanged
    {
        public ObservableCollection<VoiceLibraryViewModel> VoiceLibraryList { get; set; } = new ObservableCollection<VoiceLibraryViewModel>();
        bool sign = true;
        string alreadyinlist = "";
        public CommandEdit()
        {
            InitializeComponent();
        }
        #region INotifyPropertyChanged 接口实现

        public event PropertyChangedEventHandler PropertyChanged;
        public void OnPropertyChanged([CallerMemberName] string propName = null)
        {
            this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propName));
        }

        #endregion
        private VoiceLibraryViewModel m_SelectedVoicelibrary;
        public VoiceLibraryViewModel SelectedVoicelibrary
        {
            get { return this.m_SelectedVoicelibrary; }
            set
            {
                this.m_SelectedVoicelibrary = value;
                this.OnPropertyChanged();
            }
        }
        public class VoiceLibraryViewModel : NotifyPropertyChanged
        {
            /// <summary>
            /// 语音库索引
            /// </summary>
            private int m_ID;
            public int ID
            {
                get { return this.m_ID; }
                set
                {
                    this.m_ID = value;
                    this.OnPropertyChanged();
                }
            }
            private string m_CommandType;
            public string CommandType
            {
                get { return this.m_CommandType; }
                set
                {
                    this.m_CommandType = value;
                    this.OnPropertyChanged();
                }
            }
            private string m_CommandDescr;
            public string CommandDescr
            {
                get { return this.m_CommandDescr;}
                set
                {
                    this.m_CommandDescr = value;
                    this.OnPropertyChanged();
                }
            }
            private int m_DevType;
            public int DevType
            {
                get { return this.m_DevType;}
                set
                {
                    this.m_DevType = value;
                    this.OnPropertyChanged();
                }
            }
            private string m_DevTypeName;
            public string DevTypeName
            {
                get { return this.m_DevTypeName;}
                set
                {
                    this.m_DevTypeName = value;
                    this.OnPropertyChanged();
                }
            }
            private string m_DevTypeBranch;
            public string DevTypeBranch
            {
                get { return m_DevTypeBranch; }
                set
                {
                    this.m_DevTypeBranch = value;
                    this.OnPropertyChanged();
                }
            }
            private string m_TalkContent;
            public string TalkContent
            {
                get { return this.m_TalkContent;}
                set
                {
                    this.m_TalkContent = value;
                    this.OnPropertyChanged();
                }
            }
            private string m_KeyWords;
            public string KeyWords
            {
                get { return this.m_KeyWords;}
                set
                {
                    this.m_KeyWords = value;
                    this.OnPropertyChanged();
                }
            }
            private string m_ReplyContent;
            public string ReplyContent
            {
                get { return this.m_ReplyContent;}
                set
                {
                    this.m_ReplyContent = value;
                    this.OnPropertyChanged();
                }
            }
            private string m_CommandStep;
            public string CommandStep
            {
                get { return this.m_CommandStep;}
                set
                {
                    this.m_CommandStep = value;
                    this.OnPropertyChanged();
                }
            }
            private int m_CommandStepid;
            public int CommandStepid
            {
                get { return this.m_CommandStepid; }
                set
                {
                    this.m_CommandStepid = value;
                    this.OnPropertyChanged();
                }
            }
            private int m_LimitMatch;
            public int LimitMatch
            {
                get { return this.m_LimitMatch;}
                set
                {
                    this.m_LimitMatch = value;
                    this.OnPropertyChanged();
                }
            }
            private string m_Parameter;
            public string Parameter
            {
                get { return this.m_Parameter;}
                set
                {
                    this.m_Parameter = value;
                    this.OnPropertyChanged();
                }
            }
            public VoiceLibraryViewModel()
            {

            }

        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

            this.DataContext = this;
        }




        

        private void scrollbar_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
        {
            if (scrollbar == null)
                return;
            double num = Math.Abs((int)(e.Delta / 2));
            double offset = 0.0;
            if (e.Delta > 0)
            {
                sign = false;
                offset = Math.Max((double)0.0, (double)(scrollbar.VerticalOffset - num));
            }
            else
                offset = Math.Min(scrollbar.ScrollableHeight, scrollbar.VerticalOffset + num);
            if (offset != scrollbar.VerticalOffset)
            {
                scrollbar.ScrollToVerticalOffset(offset);
                e.Handled = true;
            }
        }


        private void BtnRef_Click(object sender, RoutedEventArgs e)
        {
            this.VoiceLibraryList.Clear();
            this.Window_Loaded(null, null);
        }

       

        private void StackPanel_Click(object sender, RoutedEventArgs e)
        {
            Button button = e.OriginalSource as Button;
            switch (button.Content.ToString())
            {
                case "新建":                   
                    VoiceLibraryViewModel viewModel = new VoiceLibraryViewModel(new VoiceLibraryModel())
                    {
                        
                    };
    
                    CommandEditView voicelibraryEdit = new CommandEditView(viewModel);
                    if (voicelibraryEdit.ShowDialog() == true)
                    {
                        this.VoiceLibraryList.Add(viewModel);
                    }
                    break;
                case "修改":
                    if (this.SelectedVoicelibrary == null)
                    {
                        return;
                    }
                    CommandEditView voicelibraryEdit1 = new CommandEditView(this.SelectedVoicelibrary);
                    voicelibraryEdit1.ShowDialog();
                    break;
                case "删除":
                    if (this.SelectedVoicelibrary == null)
                    {
                        return;
                    }
                    if (VoiceLibraryDAL.DeleteVoiceLibrary(this.SelectedVoicelibrary.ID))
                    {
                        this.VoiceLibraryList.Remove(this.SelectedVoicelibrary);
                    }
                    break;
            }
            }

        private void dgGroup_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (this.SelectedVoicelibrary == null)
            {
                return;
            }
            CommandEditView voicelibraryEdit1 = new CommandEditView(this.SelectedVoicelibrary);
            voicelibraryEdit1.ShowDialog();
        }
    }
}



//}

